package com.neu.controller;


import com.github.pagehelper.PageInfo;
import com.neu.common.Result;
import com.neu.entity.Disease;
import com.neu.entity.Params;
import com.neu.service.DiseaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 陈鲲鹏
 * @since 2025-02-08
 */
@Api(tags = "常见病管理接口")
@RestController
@RequestMapping("/disease")
public class DiseaseController {
    @Autowired
    private DiseaseService diseaseService;

    @ApiOperation("新增常见病接口")
    @PostMapping
    public Result saveDisease(@RequestBody Disease disease){


        if(disease.getId() == null){
            diseaseService.add(disease);

        }else{
            diseaseService.update(disease);

        }

        //diseaseService.add(disease);
        return Result.success();
    }

//    @ApiOperation("删除常见病接口")
//    @DeleteMapping("{id}")
//    public Result deleteDiseaseById(@ApiParam("常见病id") @PathVariable("id") Long id){
//        diseaseService.removeById(id);
//        return Result.success();
//    }

    //员工信息分页查询,基于mybatis_plus插件进行分页查询
    @GetMapping("/page")
    public Result page(Params params){
        PageInfo<Disease> info = diseaseService.findBySearch(params);
        return Result.success(info);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        diseaseService.delete(id);
        return Result.success();
    }

}
